'''
Created on 18/09/2011

@author: godinho
'''

class Direction:
    #
    # Values to these constants weren't a random choose. It is the direction
    # clockwise position on wind rose. In this way it is easy to calculate
    # opposition direction and things like these.
    #
    # Opposite direction = (direction+4)%8
    N  = 0
    NE = 1
    E  = 2
    SE = 3
    S  = 4
    SW = 5
    W  = 6
    NW = 7
    NAMES = ["N", "NE", "E", "SE", "S", "SW", "W", "NW"]
    
    @staticmethod
    def opposite(direction) :
        """
        Returns opposite direction
        Example: For North, this method would return South and so on.
        """
        return (direction+4)%8
    
    @staticmethod
    def validate(direction) :
        if direction < Direction.N or direction > Direction.NW :
            raise ValueError("Unknown direction value {0}", direction)
        
    @staticmethod
    def description(direction) :
        return Direction.NAMES[direction]
    
        